<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
       input{
           display: block;
           outline: none;
           height: 40px;
           width: 250px;
           margin: 10px auto;
       }
       #button{
           width: 140px;
           height: 50px;
           background-color: deeppink;
           margin: 10px auto;
           display: block;
           border: 0;
       }
    </style>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<form action="/empadd" method="post">
    <input type="text" placeholder="请输入姓名" name="ename" id="ename">
    <input type="text" placeholder="请输入职位" name="job" id="job">
    <input type="date" placeholder="请输入入职时间" name="hiredate" id="hiredate">
    <input type="text" placeholder="请输入薪资" name="sal" id="sal">
    <input type="text" placeholder="请输入部门" name="dname" id="dname">
    <button type="button" id="button">添加</button>
</form>
<script>
    $("#button").click(function(){
        $.ajax({
            type:"post",
            url:"/empadd",
            dataType:"json",
            data:{
                "ename":$("#ename").val(),
                "job":$("#job").val(),
                "hiredate":$("#hiredate").val(),
                "sal":$("#sal").val(),
                "dname":$("#dname").val(),
            },
            success:function(data){
                if (data>0){
                    alert("添加成功！")
                    location.href="emp.html"
                }else{
                    alert("添加失败！")
                    location.href="addemp.html"
                }
            },
            error:function(){
                alert("添加失败！")
                location.href="addemp.html"
            }
        })
    })

</script>
</body>
</html>